<template>
  <div>
    <el-table :data="course" style="width: 100%" border>
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="coursesId" label="课程编号"> </el-table-column>
      <el-table-column prop="coursesName" label="课程名称" width="400">
      </el-table-column>
      <el-table-column prop="teacherName" label="教师名称" width="400">
      </el-table-column>

      <el-table-column label="操作" width="280" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit"
            >添加</el-button
          >

          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="removeDataById(scope.row.coursesId)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :current-page="current"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center"
      layout="total, prev, pager, next, jumper"
      @current-change="getCourseList"
    />
  </div>
</template>

<script>
import testApi from "@/api/test";
export default {
  data() {
    return {
      course: [],
      current: 1,
      limit: 10,
      total: 0,
      searchObj: {},
    };
  },
  created() {
    this.getCourseList();
  },
  methods: {
    getCourseList(page = 1) {
      this.current = page;
      testApi
        .getCourseList(this.current, this.limit, this.searchObj)
        .then((res) => {
          this.course = res.data.rows;
          this.total = res.data.total;
        });
    },
    removeDataById(id) {
      this.$confirm(
        "检测到未保存的内容，是否在离开页面前保存修改？",
        "确认信息",
        {
          distinguishCancelAndClose: true,
          confirmButtonText: "删除",
          cancelButtonText: "放弃修改",
        }).then(() => {
          var ids = [];
          ids.push(id);
          testApi.deleteCourse(ids).then((res) => {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.getCourseList(this.current);
          });
        })
      ;
    },
  },
};
</script>

<style>
</style>